package net.xo68.destiny.contract.enums.user;

import net.xo68.destiny.contract.domain.user.UserRole;

/**
 * 用户角色枚举
 * @author wuxie
 * @version 2020-11-7
 */
public enum UserRoleEnum {

    ROLE_ADMIN(0,"超管"),
    ROLE_MANAGER(1,"管理员"),
    ROLE_USER(2,"普通用户"),
    ROLE_UNKNOWN(9,"未知");

    private final int code;
    private final String tag;

    UserRoleEnum(int code, String tag) {
        this.code = code;
        this.tag = tag;
    }

    public int getCode() {
        return code;
    }

    public String getTag() {
        return tag;
    }

    public UserRole getUserRole(){
        UserRole userRole=new UserRole();
        userRole.setName(name());
        userRole.setTag(tag);
        return userRole;
    }

    public static UserRoleEnum of(int code){
        for (UserRoleEnum recordType: UserRoleEnum.values()){
            if(code == recordType.getCode()){
                return recordType;
            }
        }
        return UserRoleEnum.ROLE_UNKNOWN;
    }
}
